<script setup>
import {
    Edit,
    Delete,
    Search
} from '@element-plus/icons-vue'

import { ref } from 'vue'

//导入消息框
import {ElMessage,ElMessageBox} from 'element-plus'
import {getSelectListService1} from'@/api/adm/sports_apply.js'
import {getDeptListService} from '@/api/adm/student.js' 
import { getPageService,updateChange } from '@/api/adm/sports_apply.js'
import {getSelectListService} from '@/api/sportsProject/sportsProject.js'
import { onMounted } from 'vue';
//分页条数据模型
const currentPage = ref(1)//当前页
const total = ref(20)//总条数
const pageSize = ref(5)//每页条数
const loading = ref(true)
//学期下拉框数据
const yearTerm=ref('20232')
const yearList=ref([])
//院系ID
const checkDeptID=ref(null)
const select=ref([])
const deptList=ref([])
const page=ref()
const checkProjectID=ref()
const keyWord=ref(null)
//当每页条数发生了变化，调用此函数
const onSizeChange = (size) => {
    pageSize.value = size
    getPage()
}
//当前页码发生变化，调用此函数
const onCurrentChange = (num) => {
    currentPage.value = num
    getPage()
}
const getPage=async()=>{
    const model={
        currentPage: currentPage.value?currentPage.value:1,
        pageSize: pageSize.value?pageSize.value:1,
        deptID:checkDeptID.value?checkDeptID.value:null,
        keyword:keyWord.value?keyWord.value:null,
        yearTermID:yearTerm.value?yearTerm.value:null,
        sportsID:checkProjectID.value
    }
    let result=await getPageService(model)
    page.value=result.data.records
    loading.value=false
    total.value=result.data.total
}
const getSelectList =async () =>{
    let result = await getSelectListService();
    //渲染下拉框数据
    yearList.value = result.data;
}
const getSelect= async()=>{
    const model={
        yearTermID:yearTerm.value
    }
    let result= await getSelectListService1(model)
    select.value=result.data
    checkProjectID.value=select.value[0]?.sportsID
}
const getDeptList = async ()=>{
    let result = await getDeptListService();
    deptList.value=result.data
    checkDeptID.value=deptList.value[0].deptID
}
//页面加载时调用
onMounted(
    ()=>{
        getSelectList().then(()=>{
            getSelect().then(()=>{
                getDeptList().then(()=>{
                    getPage()
                })
            })
        })
    }
)
const checkDept=()=>{
    getPage()
}
const checkProject=()=>{
    getPage()
}
const updateChange1 = async(row)=>{
    console.log(1)
    let result=await updateChange({applyID:row.applyID})
    ElMessage.success(result.data? result.data:'修改成功')
    getPage()
}
//入学年份
</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span><strong>运动会报名情况</strong></span>
            </div>
        </template>
        <!-- 搜索表单 -->
        <el-form inline>
            <el-form-item label="学期" style="width: 250px;">
                <el-select v-model="yearTerm" class="m-2" placeholder="全部"  @change="checkYear" disabled="false">
                <el-option
                        v-for="item in yearList"
                        :key="item.yearTermID"
                        :label="item.yearTermName"
                        :value="item.yearTermID"
                />
            </el-select>
            </el-form-item>
            <el-form-item label="学院"style="width: 280px;">
                <el-select v-model="checkDeptID" class="m-2" placeholder="全部"  @change="checkDept">
                <el-option
                        v-for="item in deptList"
                        :value="item.deptID"
                        :key="item.deptID"
                        :label="(item.deptID?item.deptID+'|':'')+item.deptName"
                />
            </el-select>
            </el-form-item>
            <el-form-item label="运动项目"style="width: 200px;">
                <el-select v-model="checkProjectID" class="m-2" placeholder="全部"  @change="checkProject">
                <el-option
                        v-for="item in select"
                        :value="item.sportsID"
                        :key="item.sportsID"
                        :label="item.sportsName"
                />
            </el-select>
            </el-form-item>
        </el-form>
        <el-form inline>
            <el-form-item label="学号或姓名(模糊查询)">
                <el-input placeholder="请输入信息" v-model="keyWord" :suffix-icon="Search"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary"@click="getStudentPage()">搜索</el-button>
                <el-button @click="keyWord='',checkDeptID=null,checkProject=null,getPage()">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- 学生列表 -->
        <el-table  v-loading="loading"
                element-loading-text="Loading..."
                :element-loading-spinner="svg"
                element-loading-svg-view-box="-10, -10, 50, 50"
                :row-class-name="tableRowClassName"
                :data="page" style="width: 100%">
                <el-table-column type="index" width="55" label="序号"/>
            <el-table-column label="学期" prop="yearTermID" width="100%"></el-table-column>
            <el-table-column label="报名项目" prop="sportsName" show-overflow-tooltip></el-table-column>
            <el-table-column label="项目类型">
                <template #default="{ row }">
                    <el-text class="mx-1" type="primary"v-if="row.type ===1">单人项目</el-text>
                    <el-text class="mx-1" type="warning"v-else>团队项目</el-text>
                 </template>
            </el-table-column>
            <el-table-column label="学工号" prop="userID" show-overflow-tooltip> </el-table-column>
            <el-table-column label="姓名" prop="name"width="100%"></el-table-column>
            <el-table-column label="学院" prop="deptName"show-overflow-tooltip></el-table-column>
            <el-table-column label="是否同意" show-overflow-tooltip>
                <template #default="{ row }">
                    <el-checkbox type="selection" width="55"
                    v-if="row.flag===0"  @click="" value="ture"size="large"
                    />
                    <el-checkbox type="selection" width="55"
                    v-eles checked  @click=""  size="large"
                    />
                </template>
            </el-table-column>
            <el-table-column label="操作" width="100">
                <template #default="{ row }">
                    <el-button  type="primary" @click="updateChange1(row)" v-if="row.flag==1">同意</el-button>
                    <el-button  type="success" @click="deletProjectByID(row)" v-if="row.flag==3">查看成绩</el-button>
                    <p v-if="row.flag==2">待参赛</p>
                </template>
            </el-table-column>
            <template #empty>
                <el-empty description="未查找到数据" />
            </template>
        </el-table>
        <!-- 分页条 -->
        <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[5, 7 ,9]"
            layout="jumper, total, sizes, prev, pager, next" background :total="total" @size-change="onSizeChange"
            @current-change="onCurrentChange" style="margin-top: 20px; justify-content: flex-end" />
    </el-card>
</template>
<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    box-sizing: border-box;

    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .el-table .warning-row {
        --el-table-tr-bg-color: var(--el-color-warning-light-9);
    }
    .el-table .success-row {
        --el-table-tr-bg-color: var(--el-color-success-light-9);
    }
}
</style>